import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;


public class NIO {
    public static void main(String[] args) throws IOException, InterruptedException {
    	long time = System.currentTimeMillis();
    	FileInputStream in = new FileInputStream(args[1]);
    	FileChannel can = in.getChannel();
    	if (can.size() > Integer.MAX_VALUE) {
    		throw new RuntimeException();
    	}
    	ByteBuffer buff = ByteBuffer.allocate((int)can.size());
    	int pp = can.read(buff);
    	buff.flip();
    	in.close();
    	FileOutputStream out = new FileOutputStream(args[0]);
    	FileChannel canOut = out.getChannel();
    	int pp1 = canOut.write(buff);
    	out.close();
    	System.out.println(System.currentTimeMillis() - time);
    }
}
